from django.db import models

# A project
class Project(models.Model):
	title = models.CharField(maxlength=100)
	description = models.CharField(maxlength=300)
	url = models.CharField(maxlength=100)
	completiondate = models.DateTimeField('Completion Date')
	priority = models.IntegerField()
	version = models.CharField(maxlength=30)
	completed = models.BooleanField()
	# String output for class
	def __str__(self):
		return self.title
	#Is this project due this month?
	def due_this_month(self):
		return (self.completiondate - datetime.date.today())<30
	class Admin:
		fields = (
			('Project Information', {'fields': ('title', 'description', 'url','version')}),
			('Completion Information', {'fields': ('completiondate','priority',)}),
		)
		list_display = ('title', 'priority', 'completiondate')
		list_filter = ['completiondate','priority']
		search_fields = ['title', 'description']
		date_hierarchy = 'completiondate'
	
# A user-defined field for a project
class GenericField(models.Model):
	project = models.ForeignKey(Project, edit_inline=models.TABULAR, num_in_admin=2, num_extra_on_change=2)
	fieldname = models.CharField(maxlength=30, core=True)
	value = models.CharField(maxlength=300, core=True)
	
	def __str__(self):
		return self.fieldname
	
# An item to do
class ToDo(models.Model):
	project = models.ForeignKey(Project, edit_inline=models.TABULAR, num_in_admin=2, num_extra_on_change=2)
	item = models.CharField(maxlength=100, core=True)
	priority = models.IntegerField()
	completed = models.BooleanField()
	
	def __str__(self):
		return self.item
	
class Setting(models.Model):
	name=models.CharField(maxlength=50, core=True)
	value=models.CharField(maxlength=150, core=True)
	description=models.CharField(maxlength=250, core=True)
	
	class Admin:
		pass
	
	def __str__(self):
		return self.name